/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.impl;

import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dao.TipoHabitacionDao;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.hibernate.HibernateUtil;
import java.util.List;
import ar.edu.unju.fi.reservahabitaciones.grupo14.struts.modelo.dominio.TipoHabitacion;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author mauriljb
 */
public class TipoHabitacionDaoImpl implements TipoHabitacionDao {
    
    @Override
     public List<TipoHabitacion> getAll() {
            Session session = ar.edu.unju.fi.reservahabitaciones.grupo14.struts.hibernate.HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Criteria criteria = session.createCriteria(TipoHabitacion.class);
            criteria.addOrder(Order.asc("tipoHabitacionId"));
            List<TipoHabitacion> lista = criteria.list();
            session.close();
            return lista;
    }
     
    @Override
      public TipoHabitacion getTipoHabitacion(long id) {
       Session session = HibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       Criteria criteria = session.createCriteria(TipoHabitacion.class);
       criteria.add(Restrictions.eq("id", id));
       TipoHabitacion tipoh = (TipoHabitacion) criteria.list().get(0);
       session.close();
       return tipoh;
    }
      
    @Override
      public void insert(TipoHabitacion tipoh) {
       Session session = HibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       session.save(tipoh);
       session.getTransaction().commit();
       session.close();
    }
      
    @Override
      public void delete(TipoHabitacion tipoh) {
       Session session = HibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       session.delete(tipoh);
       session.getTransaction().commit();
       session.close();
    }
       
    @Override
      public void update(TipoHabitacion tipoh) {
       Session session = HibernateUtil.getSessionFactory().openSession();
       session.beginTransaction();
       session.update(tipoh);
       session.getTransaction().commit();
       session.close();
    }
      
    
}
